home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / misc / wt004wc / dos-keyb.c < prev    next >
C/C++ Source or Header  |  1994-05-27  |  4KB  |  172 lines

  1. /*
  2. **  wt -- a 3d game engine
  3. **
  4. **  Copyright (C) 1994 by Chris Laurel
  5. **  email:  claurel@mr.net
  6. **  snail mail:  Chris Laurel, 5700 W Lake St #208,  St. Louis Park, MN  55416
  7. **
  8. **  This program is free software; you can redistribute it and/or modify
  9. **  it under the terms of the GNU General Public License as published by
  10. **  the Free Software Foundation; either version 2 of the License, or
  11. **  (at your option) any later version.
  12. **
  13. **  This program is distributed in the hope that it will be useful,
  14. **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. **  GNU General Public License for more details.
  17. **
  18. **  You should have received a copy of the GNU General Public License
  19. **  along with this program; if not, write to the Free Software
  20. **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22.  
  23. /* Modified from linux-console.c by Petteri Kangaslampi
  24.  * <pekanga@freeport.uwasa.fi>
  25. */
  26.  
  27. #include <stdlib.h>
  28. #include <dos.h>
  29. #include <string.h>
  30. #include <conio.h>
  31. #include "wt.h"
  32. #include "error.h"
  33. #include "input.h"
  34. #include "dos-keyb.h"
  35.  
  36.  
  37. static void add_special(Intent *intent, int special);
  38.  
  39. static Boolean rotating_cw = False;
  40. static Boolean rotating_ccw = False;
  41. static Boolean moving_forward = False;
  42. static Boolean moving_backward = False;
  43. static Boolean running = False;
  44. static Boolean strafing = False;
  45.  
  46.  
  47. unsigned char   kbPressed[128];         /* 1 for each keyboard scancode if
  48.                                            the key is being held down, 0 if
  49.                                            not */
  50. int             kbInitialized = 0;
  51.  
  52. (__interrupt __far *kbOldInterrupt)();
  53.  
  54. void __interrupt __far kbInterrupt(void)
  55. {
  56.     unsigned char c;
  57.  
  58.     c = inp(0x60);
  59.     kbPressed[c & 0x7F] = (c >> 7) ^ 1;
  60.  
  61.     c = inp(0x61);
  62.     outp(0x61, c | 0x80);
  63.     outp(0x61, c & 0x7F);
  64.  
  65.     outp(0x20, 0x20);
  66. }
  67.  
  68.  
  69. void init_input_devices(void)
  70. {
  71.     atexit(&end_input_devices);         /* make sure that keyboard interrupt
  72.                                            vector will be restored */
  73.     kbOldInterrupt = _dos_getvect(9);
  74.     _dos_setvect(9, kbInterrupt);
  75.     kbInitialized = 1;
  76.     memset(&kbPressed, 0, 128);
  77. }
  78.  
  79.  
  80. void end_input_devices(void)
  81. {
  82.     if ( kbInitialized )
  83.         _dos_setvect(9, kbOldInterrupt);
  84. }
  85.  
  86.  
  87. Intent *read_input_devices(void)
  88. {
  89.      static Intent intent;
  90.  
  91.      intent.force_x = intent.force_y = intent.force_z = 0.0;
  92.      intent.force_rotate = 0.0;
  93.      intent.n_special = 0;
  94.  
  95.       rotating_ccw = False;
  96.       rotating_cw = False;
  97.       moving_forward = False;
  98.       moving_backward= False;
  99.       running= False;
  100.       strafing= False;
  101.  
  102.     if ( kbPressed[kbLeftArrow] )
  103.         rotating_ccw = True;
  104.     else
  105.         rotating_ccw = False;
  106.  
  107.     if ( kbPressed[kbRightArrow] )
  108.         rotating_cw = True;
  109.     else
  110.         rotating_cw = False;
  111.  
  112.     if ( kbPressed[kbUpArrow] )
  113.         moving_forward = True;
  114.     else
  115.         moving_forward = False;
  116.  
  117.     if ( kbPressed[kbDownArrow] )
  118.         moving_backward = True;
  119.     else
  120.         moving_backward = False;
  121.  
  122.     if ( kbPressed[kbLeftShift] || kbPressed[kbRightShift] )
  123.         running = True;
  124.     else
  125.         running = False;
  126.  
  127.     if ( kbPressed[kbSpace] )
  128.         add_special(&intent, INTENT_JUMP);
  129.  
  130.     if ( kbPressed[kbAlt] )
  131.         strafing = True;
  132.     else
  133.         strafing = False;
  134.  
  135.     if ( kbPressed[kbEsc] || kbPressed[kbQ] )
  136.         add_special(&intent, INTENT_END_GAME);
  137.  
  138.      if (rotating_cw) {
  139.       if (strafing)
  140.            intent.force_y -= 0.5;
  141.       else
  142.            intent.force_rotate -= 0.5;
  143.      }
  144.      if (rotating_ccw) {
  145.       if (strafing) {
  146.            intent.force_y += 0.5;
  147.       } else
  148.            intent.force_rotate += 0.5;
  149.      }
  150.      if (moving_forward)
  151.       intent.force_x += 0.5;
  152.      if (moving_backward)
  153.       intent.force_x -= 0.5;
  154.      if (running) {
  155.       intent.force_x *= 2.0;
  156.       intent.force_y *= 2.0;
  157.       intent.force_z *= 2.0;
  158.       intent.force_rotate *= 2.0;
  159.      }
  160.  
  161.      return &intent;
  162. }
  163.  
  164.  
  165. void add_special(Intent *intent, int special)
  166. {
  167.      if (intent->n_special < MAX_SPECIAL_INTENTIONS) {
  168.       intent->special[intent->n_special] = special;
  169.       intent->n_special++;
  170.      }
  171. }
  172.